Hydrogels, such as biodegradable hydrogels, are useful in many applications including biomedical and pharmaceutical applications. Typically, a hydrogel is formed of a three-dimensional (3D) network (matrix) of a hydrophilic polymeric material, which can swell in water and hold a significant amount of water while maintaining its general network structure. The network structure may be linked together through chemical or physical links. A 3D network can be formed by crosslinking hydrophilic polymers via covalent bonds, hydrogen bonding, van der Waals interactions, or physical entanglement. Hydrogels have been prepared in situ using various methods. For instance, gelation of the precursor solution may be initiated using a chemical initiator, light, or heat. However, each existing technique for preparation of hydrogels suffers some shortcomings. For example, hydrogels prepared by some techniques are not biodegradable, which limits their application; some techniques are difficult or impossible to apply in situ; some techniques involve a complicated gel process in which it is difficult to control the formation process and the properties of the resulting hydrogel.